package com.seecen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seecen.pojo.Seeking;
import com.seecen.service.SeekingService;
import com.seecen.mapper.SeekingMapper;
import com.seecen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 桃子
* @description 针对表【pet_seeking】的数据库操作Service实现
* @createDate 2025-07-21 14:26:52
*/
@Service
public class SeekingServiceImpl extends ServiceImpl<SeekingMapper, Seeking>
    implements SeekingService{

    @Autowired
    private SeekingMapper seekingMapper;

    @Override
    public Result publishSeeking(Seeking seeking) {

        return null;
    }

    @Override
    public Result getSeeking() {
        List<Seeking> seekings = seekingMapper.selectList(null);
        return Result.ok(seekings);
    }

    @Override
    public Result saveSeek(Seeking seeking) {
        seekingMapper.insert(seeking);
        return Result.ok(null);
    }

    @Override
    public Result getSeekById(Integer id) {
        Seeking seeking = seekingMapper.selectById(id);
        Seeking seeking1 = new Seeking();
        seeking1.setSeekTableId(seeking.getSeekTableId());
        seeking1.setVersion(seeking.getVersion());
        LambdaQueryWrapper<Seeking> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Seeking::getSeekTableId,seeking1.getSeekTableId());
        seekingMapper.update(seeking1,wrapper);
        return Result.ok(seeking);

//        Headline hl = new Headline();
//        hl.setHid((Integer)headline.get("hid"));
//        hl.setVersion((Integer)headline.get("version"));
//        hl.setPageViews((Integer)headline.get("pageViews") + 1);
//
//        LambdaQueryWrapper<Headline> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(Headline::getHid,hl.getHid());
//        headlineMapper.update(hl,wrapper);
//        return Result.ok(headline);
    }
}




